<?php

class Admin_Forms_EditNoteGroupForm extends Zend_Form{
	private $_messagesError = null;

	public function __construct($option=null,$listgroup=null){
        $this->setAction('')
				->setMethod('POST')
				->setAttrib('enctype', 'multipart/form-data')
				->setAttrib('class', 'form-horizontal')
                                ->setAttrib('style','float:left')
			    ->setAttrib('name', 'addnotegroup-form');
		$groupname = $this->createElement('text', 'groupname');
		$groupname->addValidator('NotEmpty');
		$groupname->getValidator('NotEmpty')->getMessages('Xin điền tên group note');
		$groupname->setRequired ( true )
		->addFilter('StringTrim')
                ->setValue($option[0]['name_group'])
		->setAttrib('class', 'input-xlarge')
		->setLabel('Group Name');
		
		//load category
		
		$category = new Zend_Form_Element_Select('GroupNoteID');
		
		$category->setLabel('Thuộc nhóm')
                ->setValue($option[0]['GroupNoteID'])
                ->setRequired(true);
                $category->addMultiOption(0,'Không có');
		foreach ($listgroup as $data) {
			$category->addMultiOption($data['GroupNoteID'], $data['name_group']);
		}
                $main_event = new Zend_Form_Element_Select('main_event');
		$main_event->addMultiOption(0,'Không');
                $main_event->addMultiOption(1,'Có');
		$main_event->setLabel('Cho hiện box')
		->setRequired(true)
                ->setValue($data['main_event']);
		
                $images_full = new Zend_Form_Element_Select('images_full');
		$images_full->addMultiOption(0,'Không');
                $images_full->addMultiOption(1,'Có');
		$images_full->setLabel('Cho ảnh full màn hình')
		->setRequired(true)
                ->setValue($data['images_full']);
                $onlyadminpost = new Zend_Form_Element_Select('onlyadminpost');
		$onlyadminpost->addMultiOption(0,'Không');
                $onlyadminpost->addMultiOption(1,'Có');
		$onlyadminpost->setLabel('Chỉ cho admin post')
		->setRequired(true)
                ->setValue($data['onlyadminpost']);
		//

		//
		$allowed_tags = array(
				'a' =>	array('href', 'title'),
				'strong',
				'img'	=>	array('src', 'alt'),
				'ul',
				'ol',
				'li',
				'em',
				'u',
				'strike');
		
		$feature = new Zend_Form_Element_Textarea('feature');
		$feature->setLabel('Thông số')
		->setAttrib('rows', 12)
		->setAttrib('cols', 40)
		->setRequired(true)
		->addFilter('StringTrim')
		->addFilter('StripTags', $allowed_tags);
		$feature->setAttrib('class','ckeditor');
// 		$feature =$this->createElement('textarea','feature');
// 		$feature->setRequired ( true )
// 		->addFilter('StringTrim')
// 		->setAttrib('class', 'input-xlarge')
// 		->setAttrib('style', 'height:60px')
// 		->setLabel('Thông số');
		$orderdate = $this->createElement('text', 'orderdate',array('id'=>'datepicker'));
		$orderdate->addValidator(
								'NotEmpty',
								true,
								array('messages' => array('isEmpty' => 'Ngày mua không được để trống'))
						)
						->setLabel('Ngày mua')
		->setValue(date('d-m-Y',time()));

		$checkdate = $this->createElement('text', 'checkdate',array('id'=>'checkdate'));
		$checkdate->addValidator(
				'NotEmpty',
				true,
				array('messages' => array('isEmpty' => 'Ngày kiểm tra không được để trống'))
		)
		->setLabel('Ngày kiểm tra')
		->setValue(date('d-m-Y',time()));

		
		//->setDecorators($this->decorators);
		//$form is a Zend_Form object instance
		
		$avatar =$this->createElement("file", "avatar");
		$avatar
		 	  ->setLabel('Xin chọn ảnh group')
		 	  ->setDestination(APPLICATION_PATH.'/../public/images/thaoluan/');
		$avatar->addValidator(new Zend_Validate_File_Extension(array('gif,png,jpg')));
		$avatar->addValidator(new Zend_Validate_File_FilesSize(array('min'=>1,'max'=>10000000,'bytestring'=>true)));
	    $avatar->setAttrib('class','fileupload fileupload-new');
		$cancel = $this->createElement('button', 'cancel',array('label'	=> 'Hủy bỏ','class'=>'btn btn-inverse','onclick'	=> 'windown:location = "' .'/admin/note/list-group'. '"'));
		$reset = $this->createElement('reset','reset',array('label'	=> 'Reset','class'=>'btn'));
		$submit = $this->createElement('submit','submit',array ('label' => 'Sửa'));
		$submit->setAttrib('class', 'btn btn-primary');		

//SEO
		$seo_title = $this->createElement('text', 'seo_title');
		$seo_title->setLabel('SEO Title')
				  ->setValue($option[0]['seo_title']);

		$seo_keywords = $this->createElement ( 'textarea', 'seo_keywords');
		$seo_keywords->setOptions(array('cols' => '40', 'rows' => '4'));
        $seo_keywords->setLabel("SEO Keywords")
        			 ->setValue($option[0]['seo_keywords']);
		
        $seo_description = $this->createElement ( 'textarea', 'seo_description');
        $seo_description->setOptions(array('cols' => '40', 'rows' => '4'));
        $seo_description->setLabel("SEO Description")
        				->setValue($option[0]['seo_description']);


                $this->addElement($category)->addElement($groupname);
		//$this->addElement(new Element_CategorySelect('CatID'));
//		$this->addElement($ccode)
//		->addElement($quantity);
		$this
                ->addElement($main_event)
                ->addElement($images_full)
                ->addElement($onlyadminpost)        
		->addElement($avatar)
		->addElement($seo_title)
		->addElement($seo_keywords)
		->addElement($seo_description)
		
		->addElement($cancel)
		->addElement($reset)
		->addElement($submit);
		$this->setDecorators(array('FormElements',array('HtmlTag',array('tag'	=> 'div','width'=>'100%')),'form'));
		$this->setElementDecorators(array(
				'ViewHelper',
				'Errors',
				'Description',
				array(
						array('data'	=> 'HtmlTag'),
						array('tag'		=> 'div','class'	=> 'controls')),
				array('label',
						array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
				array(
						array('row'	=> 'HtmlTag',),
						array('class'=>'control-group ')
				),
				array(
						array('ErrorsDiv' => 'HtmlTag'),
						array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
				)
		)
		);
		
		$this->getElement('avatar')->setDecorators(
				array(
						'File',
						'Errors',
						array(
						array('data'	=> 'HtmlTag'),
						array('tag'		=> 'div','class'	=> 'controls')),
				array('label',
						array('class'	=> 'control-label','requiredSuffix'=>'(*)')),
				array(
						array('row'	=> 'HtmlTag',),
						array('class'=>'control-group ')
				),
				array(
						array('ErrorsDiv' => 'HtmlTag'),
						array('tag' => 'span', 'placement' => Zend_Form_Decorator_Abstract::APPEND)
				)
				)
		);
		$submit->setDecorators(array(
				'ViewHelper',
		));
		$reset->setDecorators(array(
				'ViewHelper',
		));
		$cancel->setDecorators(array(
				'ViewHelper',
		)
		);
		$this->addDisplayGroup(array('submit','reset','cancel'),'action');
		$action = $this->getDisplayGroup('action');
		$action->setDecorators(array(
				'FormElements',
				'Fieldset',
				array('HtmlTag',array('tag'=>'div','class'	=> 'form-actions'))
		));
	}
	public function isError(){
		if (count($this->_messagesError)>0){
			return true;
		}
		else
			return false;
	}
	
	//tra ve mot mang cac loi
	public function getMessagesError(){
		return $this->_messagesError;
	}
        
}   
?>
